package com.bsdsma.fengheguaiapp.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.bsdsma.fengheguaiapp.enums.Role;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 用户表
 */
@Data
@Entity
@Table(name = "t_user", indexes = @Index(name = "idx_un_account", columnList = "account", unique = true))
@TableName("t_user")
@KeySequence(dbType = DbType.MYSQL)
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键ID 自增
     */
    @Id
    @Column(length = 20)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 账号
     */
    @Column(updatable = false, length = 20, nullable = false)
    private String account;
    /**
     * 密码
     */
    @Column(length = 100, nullable = false)
    private String password;

    /**
     * 角色
     */
    @Column(nullable = false)
    private Integer role;
    /**
     * 头像图片key
     */
    @Column(name = "head_img_key", columnDefinition = "varchar(200) not null DEFAULT ''")
    private String headImgKey;

    /**
     * 创建时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date ct;
    /**
     * 更新时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date ut;

    /**
     * 姓名
     */
    @Column(length = 20, nullable = false)
    private String name;

    /**
     * 手机号
     */
    @Column(name = "cellphone_number", length = 20, nullable = false, columnDefinition = "")
    private String cellphoneNumber;

    /**
     * 0正常 -1删除
     */
    @Column(nullable = false)
    private Integer status;

    public String getRoleStr(){
        Role roleEnum = Role.get(role);
        return null == roleEnum ? "" : roleEnum.getDesc();
    }
}
